import os
import sys

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    credit = 0
    arr = a.copy()
    count = 1
    index = i
    while count <= max(arr) and len(arr) > 0:
        if count == arr[index]:
            credit += arr.pop(index)
            if len(arr) == 0:
                break
            index = index % len(arr)
            count = 1
        else:
            index = (index + 1) % len(arr)
            count += 1
    ans = max(ans, credit)
print(ans)